package com.yy.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class DBUtil {

    //建立连接
    Connection conn;
    PreparedStatement ps;
    ResultSet rs;
    public void getConn(){
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            //建立连接
            String url="jdbc:mysql://localhost:3306/aaa?characterEncoding=UTF-8";
            String name ="root";
            String pwd = "root";
            conn = DriverManager.getConnection(url, name, pwd);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
    // talk is cheap  show me the code
    //释放连接
    public void closeConn(){
        try {
            if(rs !=null){
                rs.close();
            }
            if(ps!=null){
                ps.close();
            }

            if(conn !=null){
                conn.close();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
